<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
var comboData = {
		doorCombo:null,//门牌
	}
	
	$(function() {
		$('#form').form({
			url : '/equipmentDevDnsController/add',
			onSubmit : function() {
				parent.$.messager.progress({
					title : '提示',
					text : '数据处理中，请稍后....'
				});
				var isValid = $(this).form('validate');
				if (!isValid) { 
					parent.$.messager.progress('close');
				}
				return isValid;
			},
			success : function(result) {
				parent.$.messager.progress('close');
				result = $.parseJSON(result);
				if (result.success) {
					parent.$.messager.alert('提示',result.msg,'info');
					parent.$.modalDialog.openner_dataGrid.datagrid('reload');//之所以能在这里调用到parent.$.modalDialog.openner_treeGrid这个对象，是因为resource.jsp页面预定义好了
					parent.$.modalDialog.handler.dialog('close');
				}else{
					parent.$.messager.alert('提示',result.msg,'info');
				}
			}
		});
		parent.$.messager.progress('close');
		
		// 小区
		$.ajax({
			type:'post',
			url:'/residenceController/combobox',
			data:{},
			success:function(result) {
				$('#residenceId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
				    onSelect : function(a){
						var residenceId=a.value;
						getBuildingId(residenceId);//楼栋联动，得到小区的楼栋
						getBuildingUnit(-1);
						$('#buildUnitId').combobox('setValue', '');
						$('#buildingId').combobox('setValue', '');
					}
				});
			},
			dataType:'json'
		});
		
	});
	
	
	// 楼栋
	function getBuildingId(residenceId){
		$.ajax({
			type:'post',
			url:'/buildingManager/combobox?residenceId=' +residenceId,
			data:{},
			success:function(result) {
				$('#buildUnitId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    onSelect : function(a){
						var buildingId=a.value;
						getBuildingUnit(buildingId);//单元联动，得到楼栋的单元
						$('#buildingId').combobox('setValue', '');
					} 
				});
			},
			dataType:'json'
		}); 
	}
	
	//单元
	function getBuildingUnit(buildingId) {
		$.ajax({
			type:'post',
			url:'/buildingUnitManager/combobox?parentId=' +buildingId,
			data:{},
			success:function(result) {
				data = result.buildingUnitCombo;
				$('#buildingId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto',
				    onSelect : function(a){
						var buildingUnitId=a.value;
						getDoorId(buildingUnitId);//门牌联动，得到单元的门牌信息
					} 
				});
			},
			dataType:'json'
		});
	}
	
	//门牌
	function getDoorId(buildingUnitId){//根据单元id，得到门牌信息
		$.ajax({
			type:'post',
			url:'/houseDoorplatManager/combobox?buildingUnitId=' +buildingUnitId,
			data:{},
			success:function(result) {
				data = result;
				$('#doorId').combobox({
					data : result,
					valueField:'value',   
				    textField:'text',
				    panelHeight:'auto'
				});
			},
			dataType:'json'
		});
	}
	
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
	<div data-options="region:'center',border:false" title="" style="overflow: hidden;">
		<form id="form" method="post">
			<table class="table table-hover table-condensed">
				<tr>
					<th>所属小区</th>
					<td ><input name="residenceId" id="residenceId" class="span2 " /></td>
					<th>所属楼栋</th>
					<td ><input name="buildUnitId" id="buildUnitId" class="span2 " /></td>
				</tr>
				<tr>
					<th>所属单元</th>
					<td ><input name="buildingId" id="buildingId" class="span2 " /></td>
					<th>门牌号</th>
					<td ><input name="doorId" id="doorId" class="span2 " /></td>
				</tr>
				<tr>
					<th>DDNS值</th>
					<td ><input name="ddns" id="ddns" class="span2 " /></td>
					<th>状态</th>
					<td >
						<select id="status" name="status" class="easyui-combobox" data-options="width:140,height:29,editable:false,panelHeight:'auto',icons:[{iconCls:'icon-clear',handler: function(e){$(e.data.target).combobox('setValue','');}}]">
							<option value="1">正常</option>
							<option value="2">删除</option>
						</select>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>